<?php
include("userModel.class.php");
session_start();
echo '<meta http-equiv="content-type" content="text/html;charset=utf-8">';
if(isset($_REQUEST['flag'])){
	$flag=$_REQUEST['flag'];
}
switch($flag){
	case "register":register();break;
	case "login":login();break;
}
//用户注册
function register(){
	$registerArray=array(
		'user_name'=>$_POST['user_name'],
		'user_pw'=>$_POST['user_pw']
		);
	$userModel=new UserModel();
	if($userModel->checkRegister($registerArray['user_name'])){//判断用户名是否存在
		$userModel->register($registerArray);
		echo "注册成功！";
		//header("Location:login.php");
	}else{
		echo"注册的用户名已存在";
	}
}
//用户登录
function login(){
	$user_name=$_POST['user_name'];
	$user_pw=$_POST['user_pw'];
	$userModel=new UserModel();
	$login=$userModel->checkLogin($user_name,$user_pw);
	if(isset($login)){
		$user=$userModel->selectAllUser();
		
		include("userlist.php");
		exit();
	}else{
		//header("Location:error.php");
		echo "登录失败！";
	}
}
?>